package com.cr.front.city.service.impl;

import com.cr.common.response.JsonResult;
import com.cr.front.city.dao.mapper.CarRentalCityMapper;
import com.cr.front.city.pojo.vo.CarRentalCityVO;
import com.cr.front.city.pojo.query.CarRentalCityQuery;
import com.cr.front.city.pojo.vo.CityIndexVO;
import com.cr.front.city.service.CarRentalCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


@Service
public class CarRentalCityServiceImpl implements CarRentalCityService {

    @Autowired
    private CarRentalCityMapper carRentalCityMapper;

    @Override
    public List<CarRentalCityVO> selectHotCityList() {
        List<CarRentalCityVO> list = carRentalCityMapper.selectHotCityList();
        return list;
    }

    @Override
    public List<CarRentalCityVO> selectHotCityList2() {
        List<CarRentalCityVO> list2 = carRentalCityMapper.selectHotCityList2();
        return list2;
    }

    @Override
    public Map<Character,List<CityIndexVO>> selectLetterCityList() {
        List<CityIndexVO> list = carRentalCityMapper.selectCityIndexVOList();
        Map<Character,List<CityIndexVO>> map = new LinkedHashMap<>();
        for (CityIndexVO vo : list) {
            if (vo.getPinyin() == null || vo.getPinyin().isEmpty()) {
                continue;
            }
            char first = vo.getPinyin().toUpperCase().charAt(0);
            if (map.containsKey(first)) {
                map.get(first).add(vo);
            } else {
                List<CityIndexVO> subList = new ArrayList<>();
                subList.add(vo);
                map.put(first, subList);
            }
        }
        return map;
    }

    @Override
    public CarRentalCityVO selectById(Long id) {
        return carRentalCityMapper.selectById(id);
    }
}
